package org.example;

import java.util.ArrayList;
import java.util.Scanner;

public class API_Demo4 {
    public static void main(String[] args) {
       /* ArrayList<Integer> list = new ArrayList<>();
        Scanner s = new Scanner(System.in);
        while (true) {
            System.out.println("请输入整数：");
            String numStr = s.nextLine();
            int num = Integer.parseInt(numStr);
            if (num < 1 || num > 100) {
                System.out.println("输入错误");
                continue;
            }
            list.add(num);
            int sum = getSum(list);
            if (sum > 200) {
                System.out.println("已超出范围");
                break;
            }
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }*/

        System.out.println("================1");

        Scanner s1 = new Scanner(System.in);
        String str;
        while (true) {
            System.out.println("请输入一个字符串：");
            str = s1.nextLine();
            if (!(str.matches("[0-9]\\d{0,9}"))) {
                System.out.println("输入错误");
                continue;
            } else {
                System.out.println("输入正确");
                break;
            }
        }
        int number = 0;
        for (int i = 0; i < str.length(); i++) {
            int num=str.charAt(i) - '0';
            number = number * 10 +num;
        }
        System.out.println(number);
    }





    private static int getSum(ArrayList<Integer> list) {
        int sum=0;
        for (int i = 0; i < list.size(); i++) {
            sum+=list.get(i);
        }
        return sum;
    }
}
